<?php

class ContactController extends BaseController {

    //Contact Form
    public function getContactUsForm() {

        //Get all the data and store it inside Store Variable
        $data = Input::all();

        //Validation rules
        $rules = array(
            'nombre' => 'required|max:100',
            'email' => 'required|email|max:100',
            'mensaje' => 'required|max:500'
        );

        //Validate data
        $validator = Validator::make($data, $rules);

        if($validator->fails()) {

            return Response::json([
                    'success' => false,
                    'errors' => $validator->errors()->toArray()
                ]);
        }
        else {
            Mail::send('emails.hello', $data, function ($message) use ($data) {
                //email 'From' field: Get users email add and name
                $message->from($data['email'], $data['nombre']);
                //email 'To' field: cahnge this to emails that you want to be notified.
                $message->to('estudioduplex@gmail.com', 'Karina Kreth')->subject('Consulta desde karinakreth.com');
            });

            return Response::json([
                'success' => true,
                'message' => 'El mensaje fue enviado correctamente.'
            ]);
        }



    }
}